﻿<?php
	class Emergency{
	
		private $id;
		private $event;//自然灾害catalog1
		private $type;//火灾catalog2
		private $location;
		private $time;
		private $level;//级别degree
		private $degree;
		private $leader;
		private $deputy1;
		private $deputy2;
		private $deputy3;
		//private $detail;
		private $conn;
		
		function __construct(){
			$this->conn = conn();
		}	

		public function listAll(){
				
			$query = "select * from Incident";
			$stmt = $this->conn->query( $query ); 
			$items = array();

			while ( $row = $stmt->fetch( PDO::FETCH_ASSOC ) ) {
				
				$id = $row['id'];
				$event = $row['catalog1'];
				$type = $row['catalog2'];
				$location = $row['location'];
				$time = $row['time'];
				$time = str_replace(":", "^", $time);
				$level = $row['degree'];
				$item=array("id"=>$id,"type"=>$type,"time"=>$time,"location"=>$location,"level"=>$level);				
				// var_dump($item);
				// die();
				array_push($items, $item);
			}				
			return $items;
		}

		public function getEvent($id){
			$query = "select * from Incident where id = '".$id."'";
			$stmt = $this->conn->query( $query );
			$row = $stmt->fetch( PDO::FETCH_ASSOC );
			//
			$id = $row['id'];
			$event = $row['catalog1'];
			$time = $row['time'];
			$time = str_replace(":", "^", $time);
			$location = $row['location'];
			$level = $row['degree'];
			//$detail = $row['detail'];
			$leader = $row['leader'];
			$deputy1 = $row['deputyLeader1'];
			$deputy2 = $row['deputyLeader2'];
			$deputy3 = $row['deputyLeader3'];
			
			$event_items = array("id"=>$id,"event"=>$event,"time"=>$time,"location"=>$location,"level"=>$level,
			"detail"=>'',"leader"=>$leader,"deputy1"=>$deputy1,"deputy2"=>$deputy2,"deputy3"=>$deputy3);
			
			return $event_items;
		}
		
		public function getProcess($id){
			//
			$process_items = array();
			$query = "select * from Incident_Detail where incidentId = '".$id."'";
			$stmt = $this->conn->query( $query );
			while ( $row = $stmt->fetch( PDO::FETCH_ASSOC ) ) {
				$process_id = $row['id'];			
				$process = $row['contents'];
				$time = $row['time'];
				$time = str_replace(":", "^", $time);
				$item1=array("id"=>$process_id,"process"=>$process,"time"=>$time);
				array_push($process_items, $item1);				
			}

			return $process_items;
		}
		
		public function getPlan($id){
			//
			$plan_items = array();
			//只显示火灾事项
			$query = "select * from Incident_Plan";
			$stmt = $this->conn->query( $query );
			while ( $row = $stmt->fetch( PDO::FETCH_ASSOC ) ) {
				$plan_id = $row['id'];
				$catalog2 = $row['catalog2'];
				$implementation = $row['implementation'];
				$handling = $row['handling'];
				$notes = $row['notes'];
				$hazardSources = $row['hazardSources'];
				$cases = $row['cases'];
				$item1=array("id"=>$plan_id,"catalog2"=>$catalog2,"implementation"=>$implementation,
				"handling"=>$handling,"notes"=>$notes,"hazardSources"=>$hazardSources,"cases"=>$cases);
				array_push($plan_items, $item1);						
			}			
			return $plan_items;
		}
		
		// public function update($item){
		
			// $id = $item['id'];
			// $name = $item['name'];
			// $value = $item['value'];
			// $unit = $item['unit'];
			// $year = $item['year'];
			// $month = $item['month'];
			// $query = "update Economic SET Name ='".$name."', Value = '".$value."', Unit = '".$unit."', Year = '".$year."', Month = '".$month."' where ID = '".$id."'";
			// echo $query;
			
			// $stmt = $this->conn->query( $query );
		// }		
		
		// public function insert($item){			
			// $id = $item['ID'];
			// $name = $item['name'];
			// $value = $item['value'];
			// $unit = $item['unit'];	
			// $year = $item['year'];
			// $month = $item['month'];
			// $query = "INSERT INTO Economic(Name,Year,Month,Value,Unit) VALUES('".$name."','".$year."','".$month."','".$value."','".$unit."')";
			//print_r ($query);
			// $stmt = $this->conn->query( $query );
		// }	
		
		// public function delete($id){
			// $query = "delete from Economic where ID = '".$id."'";
			// $stmt = $this->conn->query( $query );
		// }
		
		// public function getById($id){		
			// $query = "select * from Economic where ID = '".$id."'";
			// $stmt = $this->conn->query( $query );
			// $row = $stmt->fetch( PDO::FETCH_ASSOC );
			// $id = $row['ID'];
			// $name = $row['Name'];
			// $value = $row['Value'];
			// $unit = $row['Unit'];
			// $year = $row['Year'];
			// $month = $row['Month'];
			// $item=array("id"=>$id,"name"=>$name,"value"=>$value,"unit"=>$unit,"year"=>$year,"month"=>$month);
			// return $item;
		// }
		
	}
?>